package com.imooc.ecommerce.controller;

import com.imooc.ecommerce.service.hystrix.UseHystrixCommandAnnotation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * hystrix controller
 * @Author: zhangshao
 * @Since: 2023/12/6 14:41
 */
@Slf4j
@RestController
@RequestMapping("/hystrix")
public class HystrixController {

	@Autowired
	private UseHystrixCommandAnnotation hystrixCommandAnnotation;

	@GetMapping("/hystrix-command-annotation")
	public List<ServiceInstance> getNacosClientInfoUseAnnotation(@RequestParam String serviceId){
		log.info("request nacos client info use annotation: [{}],[{}]",serviceId,Thread.currentThread().getName());
		return hystrixCommandAnnotation.getNacosClientInfo(serviceId);
	}
}
